package com.jiazhong.spring.rocketmq.事务消息.生产;

import com.jiazhong.spring.rocketmq.事务消息.监听.事务消息监听;
import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.common.message.Message;

public class 事务消息发送 {
    @SneakyThrows
    public static void main(String[] args) {
        TransactionMQProducer producer = new TransactionMQProducer("transaction_group_a");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.setTransactionListener(new 事务消息监听());
        producer.start();
        for (int i = 1; i < 11; i++) {
            String topic = "TopicA";
            String tags = "transaction";
            String body = "Hello,Transaction!index:" + i;
            Message message = new Message(topic, tags, body.getBytes());
            message.setKeys("Num:" + i);
            producer.sendMessageInTransaction(message, null);
        }
    }
}
